import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;

// 服务类，包含需要在线程池中执行的任务
@Service
public class TaskService {

    // 每秒钟输出一次当前时间，持续1分钟
    public void printTimeEverySecond() {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        for (int i = 0; i < 60; i++) {
            try {
                // 输出当前时间
                System.out.println("当前时间: " + sdf.format(new Date()));
                // 休眠1秒
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                break;
            }
        }
    }

    // 倒计时1分钟
    public void countdownOneMinute() {
        for (int i = 60; i > 0; i--) {
            try {
                System.out.println("倒计时: " + i + "秒");
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                break;
            }
        }
        System.out.println("倒计时结束!");
    }
}
    